﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using System.Web;
using Skynet.BusinessLogic.BusinessComponents;

namespace Skynet.WebAdministracion.Views.ExamByCustomerDashboard
{
    public class ExamByCustomerDashboardPresenter : Infrastructure.Web.Views.Master.MasterPresenter<IExamByCustomerDashboardView>
    {
        [Dependency]
        public BusinessLogic.BusinessComponents.IBCExams BCExam { get; set; }



        [Dependency]
        public BusinessLogic.BusinessComponents.IBCExamQueries BCExamQueries { get; set; }

        [Dependency]
        public BusinessLogic.BusinessComponents.IBCCustomers BCCustomers { get; set; }

        [Dependency]
        public IBCCustomersQueries BCCustomersQueries { get; set; }

        [Dependency]
        public WebFoundation.Services.Session.ISessionService SessionService { get; set; }

        [Dependency]
        public WebFoundation.Services.Navigation.INavigationService NavigationService { get; set; }


        public override void OnViewInitialized()
        {            
            var userName = HttpContext.Current.User.Identity.Name;
            var customer = this.BCCustomersQueries.FindCustomers(option: BusinessLogic.BusinessComponents.CustomerFindOptions.GetByUserName, UserName: userName).SingleOrDefault();
            this.View.ActiveExams = (int)this.BCExamQueries.FindExamByCustomer(BusinessLogic.BusinessComponents.FindExamByCustomerOptions.ActiveExams, customer.Id);
            this.View.ResultExams = (int)this.BCExamQueries.FindExamByCustomer(BusinessLogic.BusinessComponents.FindExamByCustomerOptions.CompleteExams, customer.Id);
            this.View.RunningExams = (int)this.BCExamQueries.FindExamByCustomer(BusinessLogic.BusinessComponents.FindExamByCustomerOptions.RunningExams, customer.Id);
        }
        public void ShowActiveExams()
        {
            var userName = HttpContext.Current.User.Identity.Name;
            var customer = this.BCCustomersQueries.FindCustomers(option: BusinessLogic.BusinessComponents.CustomerFindOptions.GetByUserName, UserName: userName).SingleOrDefault();
            if (this.BCExamQueries.FindExamByCustomer(BusinessLogic.BusinessComponents.FindExamByCustomerOptions.ActiveExams, customer.Id) > 0)
            {
                this.NavigationService.Navigate("~/Evaluation/EvaluationMgm.aspx");                        
            }            
        }
        public void ShowRunningExams()
        {
            var userName = HttpContext.Current.User.Identity.Name;
            var customer = this.BCCustomersQueries.FindCustomers(option: BusinessLogic.BusinessComponents.CustomerFindOptions.GetByUserName, UserName: userName).SingleOrDefault();
            if (this.BCExamQueries.FindExamByCustomer(BusinessLogic.BusinessComponents.FindExamByCustomerOptions.RunningExams, customer.Id) > 0)
            {
                this.NavigationService.Navigate("~/Evaluation/ExamRunningMgm.aspx");
            }                     
        }
        public void ShowExamResults()
        {
            var userName = HttpContext.Current.User.Identity.Name;
            var customer = this.BCCustomersQueries.FindCustomers(option: BusinessLogic.BusinessComponents.CustomerFindOptions.GetByUserName, UserName: userName).SingleOrDefault();
            if (this.BCExamQueries.FindExamByCustomer(BusinessLogic.BusinessComponents.FindExamByCustomerOptions.CompleteExams, customer.Id) > 0)
            {
                this.NavigationService.Navigate("~/Evaluation/ExamResultMgm.aspx");
            }            
        }
    }
}
